
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using GruntXProductions;
using Viper;
using Viper.Opcodes;

namespace Diamond
{
	public partial class CodeGen 
	{
		public void ParseFor(ForStatement ifstat)
		{
			DeclareVarAndAssign(ifstat.Declaration);
			string label = "for_" + ifIndex.ToString();
			string label2 = "endfor_" + ifIndex.ToString();
			breakLabels.Push(label2);
			Symbols.BeginScope();
			ifIndex++;
			Assembler.CreateLabel(label);
			ParseBooleanExpression(ifstat.Comparison);
			Assembler.Emit(new bz(label2));
			CompileBlock(ifstat.Body);
			CompileLine(ifstat.Step);
			Assembler.Emit(new bra(label));
			breakLabels.Pop();
			Symbols.EndScope();
			Assembler.CreateLabel(label2);
		}
	}
	
}